﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication6._14
{
    public partial class Page : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RangeValidator2.MaximumValue = DateTime.Now.ToShortDateString();
        }

        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (args.Value == "admin")
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            if (Picture.HasFile)
            {
                string fileName = Picture.FileName;
                if (fileName.EndsWith(".jpg") || fileName.EndsWith(".jpeg") || fileName.EndsWith(".png") || fileName.EndsWith(".gif"))
                {
                    string url = Server.MapPath(@"~\img\"+fileName);
                    Picture.SaveAs(url);
                    LookOver.ImageUrl = @"~\img\"+fileName;
                }
                else
                {
                    ClientScript.RegisterClientScriptBlock(GetType(),"警告", "<script>alert('文件格式错误')</script>");
                    error.Text = @"文件格式错误，仅能上传jpg\jpeg\png\gif文件";
                    return;
                }
            }
            else
            {
                ClientScript.RegisterClientScriptBlock(GetType(), "警告", "<script>alert('不能上传空文件')</script>");
                error.Text = "不能上传空文件";
                return;
            }


            if (Page.IsValid)
            {
                Jump.Text = @"注册成功！<a href='\Login.aspx'>点击跳转登入页面</a>";
            }
        }
    }
}